﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <script src="../../js/load.js"></script>
</head>

<body>
    <div>
        <div id="logdiv" style=" background-color: black;    color: white; overflow-y: scroll;">
            <span id="logContent"></span>
        </div>
        <div id="opcontainer">
            <button class="layui-btn" id="btnStart" onclick="StartRefresh()" style="display: none;">开启刷新</button>
            <button class="layui-btn layui-btn-danger" id="btnStop" onclick="StopRefresh()" style="display: none;">停止刷新</button>
            <button class="layui-btn  layui-btn-primary" onclick="HandleClose()">关闭</button>
        </div>
    </div>
</body>
</html>
<script>
    var timer
    $(function () {
        $("#logdiv").height((document.body.clientHeight - 46) + "px");
        StartRefresh();
    })

    function HandleClose() {
        CloseDialog();
    }

    function BindLog() {
        var param = {
            projectID: GetUrlParam("projectID")
        }
        HttpPost(JSON.stringify(param), 'api/depoly/getRunningLog', function (result) {
            if (result.code == 0) {
                $("#logContent").html(result.data.obj);
                var element = $("#logdiv")[0]
                element.scrollTop = element.scrollHeight;
            }
        })
    }
    
    function StartRefresh() {
        timer = setInterval('BindLog()', 1000);
        $("#btnStart").hide();
        $("#btnStop").show();
    }

    function StopRefresh() {
        if (timer != null) {
            clearInterval(timer)
            timer = null
        }
        $("#btnStart").show();
        $("#btnStop").hide();
    }
</script>